#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int temp = 0;
        int flag = 0;
        int A, B, C;
        char x, y;
        cin >> A >> x >> B >> y >> C;
        if(x == '*') {
            temp = A * B;
            if(y == '*') {
                temp = temp * C;
                cout << temp << endl;
            }else {
                if(y == '-') {
                    temp = temp - C;
                    cout << temp << endl;
                }else {
                    temp = temp + C;
                    cout << temp << endl;
                }
            }
            
        }else if(x == '-'){
            if(y == '*') {
                cout << A - B * C << endl;
            }else if(y == '-') {
                cout << A - B - C << endl;
            }else {
                cout << A - B + C << endl;
            }
        }else {
            if(y == '*') {
                cout << A + B * C << endl;
            }else if(y == '-') {
                cout << A + B - C << endl;
            }else {
                cout << A + B + C << endl;
            }
        }
    }
    return 0;
}